<template>
  <div class="viewContain">
    <el-form :model="listQuery" size="small" label-width="100px">
      <el-row>
        <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 6 }" :xl="{ span: 6 }">
          <el-form-item label="账号 :">
            <el-input
              v-model="listQuery.userName"
              placeholder="请输入内容"
              clearable
              @keyup.enter.native="handleSearch"
            />
          </el-form-item>
        </el-col>
        <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 16 }" :xl="{ span: 16 }">
          <el-form-item label-width="20px">
            <el-button size="mini" type="primary" @click="handleSearch">查询</el-button>
            <el-button size="mini" type="primary" plain @click="handleReload1">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <!-- 额度修改 -->
    <el-dialog
      :title="dialogTitle"
      :visible.sync="dialogFormVisible"
      width="400px"
      :close-on-click-modal="false"
    >
      <el-form :model="formData" size="small" :rules="rules" label-width="100px">
        <el-row>
          <el-col :xs="{ span: 24 }" :sm="{ span: 24 }" :md="{ span: 24 }" :xl="{ span: 24 }">
            <el-form-item label="账号 :" prop="userName">
              <el-input v-model="formData.userName" placeholder="最多输入20字" clearable disabled style="max-width:220px" />
            </el-form-item>
          </el-col>
          <el-col :xs="{ span: 24 }" :sm="{ span: 24 }" :md="{ span: 24 }" :xl="{ span: 24 }">
            <el-form-item label="额度 :" prop="quotaNum">
              <el-input v-model="formData.quotaNum" placeholder="最多输入20字" clearable style="max-width:220px" /> %
            </el-form-item>
          </el-col>
        </el-row>
        <div style="text-align:center">
          <el-button size="mini" type="primary" plain @click="dialogFormVisible=false">取消</el-button>
          <el-button size="mini" type="primary" @click="handleSave">确定</el-button>
        </div>
      </el-form>
    </el-dialog>
    <el-table
      ref="table"
      v-loading="loading"
      fit
      stripe
      :data="tableData"
      border
      size="mini"
    >
      <el-table-column align="center" label="序号" type="index" width="50">
        <template slot-scope="scope">
          <span>{{ (listQuery.pageNo - 1) * listQuery.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="userName" align="center" label="账号" />
      <el-table-column prop="quotaNum" align="center" label="额度(%)" width="100" />
      <el-table-column prop="quotaTime" align="center" label="额度设置时间" />
      <el-table-column align="center" fixed="right" label="操作" width="200">
        <template slot-scope="scope">
          <el-button class="text-button" size="mini" @click="handleLimitSet(scope.row.userName, scope.row.quotaNum, scope.row.userId)">额度设置</el-button>
          <el-button class="text-button" size="mini" @click="handleLimitRecord(scope.row.id,scope.row.userName)">额度设置记录</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { commonMixin } from '@v/mixin/commonMixin.js'
import ComApiUrl from '@a/comomApi.js'
export default {
  mixins: [commonMixin],
  data() {
    return {
      comApiUrlList: new ComApiUrl('/member/api/quota/list'),
      comApiUrlUpdate: new ComApiUrl('/member/api/quota/add'),
      dialogFormVisible: false,
      rules: {},
      listQuery: {
        pageNo: 1,
        pageSize: 10,
        latest: 1
      },
      dialogTitle: '额度修改',
      formData: {
        userId: '',
        userName: '',
        quotaNum: ''
      }
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    // 额度设置
    handleLimitSet(userName, quotaNum, userId) {
      this.dialogFormVisible = true
      this.formData.userName = userName
      this.formData.quotaNum = quotaNum
      this.formData.userId = userId
    },
    // 额度设置记录
    handleLimitRecord(id, userName_limit) {
      localStorage.setItem('userName_limit', userName_limit)
      this.$router.push('/business/limit/record/' + id)
    },
    // 额度修改确定
    handleSave() {
      this.update()
    },
    handleReload1() {
      this.listQuery = {
        pageNo: 1,
        pageSize: 10,
        latest: 1
      }
      this.getList()
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
